const Mock = require('mockjs')

module.exports = function(app) {
  const cartData = Mock.mock({
    'list|3-10': [{
      'id|+1': 1,
      'name': '@ctitle(1, 3)',
      'price': '@natural(100, 1000)',
      'image': '@image("50x50", "#ccc", "#FFF", "png", "商品")',
      'quantity': '@natural(1, 5)',
      'model': '@ctitle(2, 4)'
    }]
  })

  app.get('/api/cart', (req, res) => {
    res.json({
      code: 0,
      data: cartData.list
    })
  })

  app.post('/api/cart/update', (req, res) => {
    const { id, quantity } = req.body
    res.json({
      code: 0,
      data: {
        id,
        quantity
      }
    })
  })
}
